#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	ui(new Ui::MainWindow)
{
	ui->setupUi(this);
	
	/* initialize process thread */
	pProcess	= new LayerProcess();
	
	/* Load last dico from ini file */
	pProcess->LoadLastDico();
	/* Check for the dico datas to enable some functions */
	BackFromUi(1);
	
}


void MainWindow::BackFromUi(int finishedCode)
{
	ui->centralWidget->setEnabled(true);
	/* Verifie si l'on peut passer en mode game */
	if(pProcess->checkDicoInit())
		ui->commandLinkButton_3->setEnabled(true);
	else
		ui->commandLinkButton_3->setEnabled(false);
}



/* DESTRUCTEUR */
MainWindow::~MainWindow()
{
	delete ui;
}



/* INTERFACE EVENTS*/
/*****************************************************************/
void MainWindow::on_commandLinkButton_2_clicked()
{
	ui->centralWidget->setDisabled(true);
	
	/* Initialize pointer on the other windows */
	uiDico		= new Dialog_Dico(this,pProcess);
	/* Connect the event */
	connect(uiDico,		SIGNAL(finished(int)),	this,		SLOT(BackFromUi(int))	);
    
	uiDico->exec();
}

void MainWindow::on_Button_Exit_clicked()
{
	this->close();
}

void MainWindow::on_commandLinkButton_3_clicked()
{
	ui->centralWidget->setDisabled(true);
	
	/* Initialize pointer on the other windows */
	uiGame		= new Dialog_Game(this,pProcess);
	/* Connect the event */
	connect(uiGame,		SIGNAL(finished(int)),	this,		SLOT(BackFromUi(int))	);
    
	uiGame->exec();
}

void MainWindow::on_commandLinkButton_clicked()
{
	ui->centralWidget->setDisabled(true);
	
	/* Initialize pointer on the other windows */
	uiResults	= new Dialog_Results(this,pProcess);
	/* Connect the event */
	connect(uiResults,	SIGNAL(finished(int)),	this,		SLOT(BackFromUi(int))	);
	
	uiResults->exec();
}
